<?php

namespace App\CustHub\Mapper;

use App\CustHub\Model\ChCtrlRoomFilterRule;
use Hyperf\Cache\Annotation\Cacheable;
use Hyperf\Config\Annotation\Value;
use Mine\Abstracts\AbstractMapper;

class ChCtrlRoomFilterRuleMapper extends AbstractMapper
{


    #[Value('cache.default.prefix')]
    protected string $prefix;

    public function assignModel()
    {
        $this->model = ChCtrlRoomFilterRule::class;
    }


    #[Cacheable(prefix: 'ctrl_room_filter_rule', value: '#{mainUid}', ttl: 16 * 60)]
    public function findByMainUid(int $mainUid): ChCtrlRoomFilterRule|\Hyperf\Database\Model\Builder|null
    {
        return $this->model::query()
            ->where('main_uid', $mainUid)
            ->first();
    }


    public function cleanCache(int $mainUid)
    {
        $redis = redis();
        $keyOne = $this->prefix . 'ctrl_room_filter_rule:'.$mainUid;
        $redis->del([$keyOne]);
    }
}